import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CaterpillarsOnTree {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();

        List<List<Integer>> tree = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            tree.add(new ArrayList<>());
        }

        for (int i = 2; i <= n; i++) {
            int fi = scanner.nextInt();
            tree.get(fi).add(i);
        }

        int[] xor = new int[n + 1];

        dfs(1, 0, tree, xor);

        int result = 0;
        for (int i = 0; i < q; i++) {
            result ^= xor[scanner.nextInt()] ^ xor[scanner.nextInt()];
        }

        System.out.println(result);
    }

    private static void dfs(int node, int parent, List<List<Integer>> tree, int[] xor) {
        xor[node] = xor[parent] ^ node;
        for (int child : tree.get(node)) {
            dfs(child, node, tree, xor);
        }
    }
}
